
#include "StdAfx.h"
#include "McDropTarget.h"

CMcDropTarget::CMcDropTarget(void)
	: m_pWnd(NULL)
	, m_nDropDataType(DD_NONE)
{
}

CMcDropTarget::~CMcDropTarget(void)
{
}

BOOL CMcDropTarget::RegisterDropTargetWindow(CWnd* pWnd)
{
	m_pWnd = pWnd;
	return m_DropTarget.Register(this);
}

void CMcDropTarget::RevokeDropTargetWindow()
{
	m_DropTarget.Revoke();
}

BOOL CMcDropTarget::GetDropData(COleDataObject* pDataObject, MC_DROP_DATA* pData)
{
	MC_DROP_DATA* pSrcData = NULL;
	HGLOBAL hGlobal = pDataObject->GetGlobalData(CF_MC_DROP_DATA);

	if(hGlobal)
	{
		pSrcData = static_cast<MC_DROP_DATA*>(GlobalLock(hGlobal));

		if(pSrcData)
		{
			*pData = *pSrcData;
			GlobalUnlock(hGlobal);
		}
	}

	return (pSrcData != NULL);
}

BOOL CMcDropTarget::CanDropData(const MC_DROP_DATA* pData)
{
	return ((pData->pSrcWnd != m_pWnd) && (pData->nType & m_nDropDataType));
}

DROPEFFECT CMcDropTarget::DragEnter(COleDataObject* pDataObject, DWORD dwKeyState, const CPoint& point)
{
	MC_DROP_DATA Data;
	if(GetDropData(pDataObject, &Data))
	{
		if(CanDropData(&Data))
		{
			return OnDragEnter(&Data, dwKeyState, point);
		}
	}

	return DROPEFFECT_NONE;
}

DROPEFFECT CMcDropTarget::DragOver(COleDataObject* pDataObject, DWORD dwKeyState, const CPoint& point)
{
	MC_DROP_DATA Data;
	if(GetDropData(pDataObject, &Data))
	{
		if(CanDropData(&Data))
		{
			return OnDragOver(&Data, dwKeyState, point);
		}
	}

	return DROPEFFECT_NONE;
}

BOOL CMcDropTarget::Drop(COleDataObject* pDataObject, DROPEFFECT dropEffect, const CPoint& point)
{
	MC_DROP_DATA Data;
	if(GetDropData(pDataObject, &Data))
	{
		if(CanDropData(&Data) && !Data.bFakeDrop)
		{
			return OnDrop(&Data, dropEffect, point);
		}
	}

	return FALSE;
}

void CMcDropTarget::DragLeave()
{
	OnDragLeave();
}

DROPEFFECT CMcDropTarget::OnDragEnter(const MC_DROP_DATA* pData, DWORD dwKeyState, const CPoint& point)
{
	return DROPEFFECT_MOVE;
}

DROPEFFECT CMcDropTarget::OnDragOver(const MC_DROP_DATA* pData, DWORD dwKeyState, const CPoint& point)
{
	return DROPEFFECT_MOVE;
}

BOOL CMcDropTarget::OnDrop(const MC_DROP_DATA* pData, DROPEFFECT dropEffect, const CPoint& point)
{
	return FALSE;
}

void CMcDropTarget::OnDragLeave()
{
}